<template>
    <div>
        <div class="headstyle">
            <el-row :gutter="24">
            <el-col :span="7">
                <div class="grid-content bg-purple">
                <span class="locsty"><i class="el-icon-location iconsty"></i>当前位置：管理员账号管理</span>
                </div>
            </el-col>
            <el-col :span="9">
                <div class="grid-content bg-purple">
                    <el-input  v-model="te_name" placeholder="请输入管理员工号" clearable></el-input>                  
                    <el-button type="primary" @click="selectTeacher">查询</el-button>
                </div>
            </el-col>
            <el-col :span="8">
                <div class="grid-content bg-purple">
                    <el-button type="primary" @click="goTo('/editadmininfo')">新增管理员</el-button>
                    <el-button type="danger" @click="deleteteacherlist()" >批量删除</el-button>
                </div>
            </el-col>
            </el-row>
        </div>
        <div class="contentstyle">
             <el-table ref="multipleTable"  :data="tableData.filter(data=>total!=0)"  
                 tooltip-effect="dark" 
                 style="width: 100%;text-align:center"
                 border @selection-change="handleSelectionChange">
                <el-table-column type="selection"  width="55" align="center"></el-table-column>
                <el-table-column  prop="te_number" label="管理员账号" show-overflow-tooltip align="center"> </el-table-column>
                <el-table-column  prop="te_name" label="管理员姓名" show-overflow-tooltip align="center"> </el-table-column>
                <el-table-column  prop="te_depart" label="管理员部门" show-overflow-tooltip align="center"> </el-table-column>
                <el-table-column  prop="te_kind" label="一级业务维度" show-overflow-tooltip align="center"> </el-table-column>               
                <el-table-column  prop="date" label="创建日期" show-overflow-tooltip align="center"> </el-table-column>               
                <el-table-column label="操作" align="center" width="200">
                    <template slot-scope="scope">
                       <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
                       <el-button  size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    v-if = "paginationShow"
                    @current-change="currentChange"
                    @size-change="sizeChange"
                    :current-page="currentPage"
                    :page-size="pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="total"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
export default {
  data() {
    return {
      te_name: "",
      pageSize: 10, // 页容量
      currentPage: 1, // 当前页
      total: 0, // 数据的总条数
      paginationShow: true, // 控制分页的显示隐藏达到刷新的效果
      sels: [], //选中显示的值
      disabled: true,
      //课程数据
      tableData: [
        {
          te_id:"",
          te_number:"",
          te_name:"",
          te_depart:"",
          te_kind:"",
          date:"",
          te_psw:""
        }
      ],
    };
  },
  //页面初次加载
  mounted: function() {
    this.selectTeacher();
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.sels = val;
    },

    //批量删除
    deleteteacherlist() {    
      var ids='';
      this.sels.forEach(element => {
        ids += element.te_id +',';
      });         
      this.$confirm("确定要删除选中的文件吗?", "提示")
        .then(() => {
          this.$axios
          .delete("/Teacher",{params:{idlist:ids}}).then(dara => {
          this.$message({
                    message: '删除成功！',
                    type: 'success'
                });
            this.selectTeacher();
          });
        })
        .catch(() => {});
    },

    //点击链接跳转
    goTo(path) {
      this.$router.replace(path);
    },


    // 当页容量发生变化时触发
    sizeChange(size) {
      this.pageSize = size;
      // 重新请求数据
      this.selectTeacher();
    },
    // 当页数发生变化时触发
    currentChange(num) {
      this.currentPage = num;
      // 重新请求数据
      this.selectTeacher();
    },
    // 查询方法
    searchClicks() {
      this.paginationShow = false;
      this.currentChange(1);
      this.$nextTick(() => {
        this.paginationShow = true;
        this.selectTeacher();
      });
    },
    //数据列表查询方法
    selectTeacher() {
        var flag
        if(this.authflag==''){
            flag = -1;
        }
        else{
            flag = this.authflag;
        }
        this.$axios     
            .get("/Teacher", {
            params: {
                page: this.currentPage,
                pageSize: this.pageSize,
                te_name: this.te_name,
                isadmin:1,
                flag:flag
            }
        })
        .then(json => {        
          var teacherlist = JSON.parse(json.data.teacherlist);
          this.total = json.data.totalpage;
          var telistdata = [];
          for (let i = 0; i < teacherlist.length; i++) {
            var item = {
              te_id: teacherlist[i].Te_id,
              te_number: teacherlist[i].Te_number,
              te_name: teacherlist[i].Te_name,
              te_depart: teacherlist[i].Te_depart,
              te_kind:teacherlist[i].Te_kind,             
              date:teacherlist[i].Te_datetime
            };
            telistdata[i] = item;
          }
          this.tableData = telistdata;
        });
    },
    //编辑
    handleEdit(index, row) {
      //this.$router.push('/coursemanage/editcourse',{params:{id:row.couid}});
      var id = row.te_id;
      this.$router.push({ name: "editadmininfo", params: { id } });
    },
    //删除，物理删除
    handleDelete(index, row) {
      var id = row.te_id;
      this.$confirm("确定要删除选中的文件吗?", "提示").then(() => {
        this.$axios
          .delete("/Teacher/" + id)
          .then(json => {
            if (json.data == 1) {
                this.$message({
                    message: '删除成功！',
                    type: 'success'
                });
                this.selectTeacher();
            }
          })
          .catch(error => {});
      });
    }
  },
  computed: {
    totalNum() {
      return this.total;
    }
  },
  watch: {
    // 监听总条数,每次查询将当前页置为 1
    totalNum(val) {
      if (val == (this.currentPage - 1) * this.pageSize && val != 0) {
        this.currentPage -= 1;
        this.selectTeacher(this);
      }
    }
  }
};
</script>


<style scoped>
.locsty {
  font-size: 16px;
  font-family: "Microsoft YaHei";
}
.editsty {
  padding: 3px;
  font-size: large;
}
.iconsty {
  color: #53b9fe;
  font-size: 22px;
}
.headstyle {
  border-bottom: 2px solid #e5e5e5;
  padding-bottom: 20px;
}
.contentstyle {
  text-align: center;
  width: 90%;
  padding: 40px;
}
.el-input {
  width: 200px;
}
</style>

